package com.ticket.sass.admin.controller;

import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.ticket.sass.admin.annotation.Loggable;
import com.ticket.sass.admin.annotation.Module;
import com.ticket.sass.admin.business.FilmScheduleBusiness;
import com.ticket.sass.admin.dto.input.FilmSortInput;
import com.ticket.sass.admin.dto.input.SaleFilmListInput;
import com.ticket.sass.admin.dto.input.film.FilmScheduleListInput;
import com.ticket.sass.admin.dto.input.film.SaleChannelInput;
import com.ticket.sass.admin.dto.input.film.SalePriceInput;
import com.ticket.sass.admin.dto.output.film.DateScheduleOutput;
import com.ticket.sass.admin.dto.output.film.FilmScheduleListOutput;
import com.ticket.sass.admin.dto.output.film.SaleFilmListOutput;
import com.ticket.sass.admin.model.PageModel;
import com.ticket.sass.admin.model.ResultModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ywb
 * @since 2024-03-06
 */
@RestController
@AllArgsConstructor
@ApiSupport(order = 1)
@Api(tags = {"影片排期数据-模块"})
@RequestMapping("/film-schedules")
public class FilmScheduleController {
    final FilmScheduleBusiness business;
    
    @ApiOperation("列表")
    @GetMapping
    public ResultModel<PageModel<FilmScheduleListOutput>> list(
        @Valid FilmScheduleListInput input
    ) {
        return ResultModel.success(
            business.list(input)
        );
    }
    
    
    @ApiOperation("日期列表")
    @GetMapping("/date")
    public ResultModel<List<DateScheduleOutput>> dateList(
    ) {
        return ResultModel.success(
            business.dateList()
        );
    }
    
    
    @PostMapping("/refresh")
    @ApiOperation("刷新")
    @Loggable(module = Module.FILM_SCHEDULE, desc = "刷新")
    public ResultModel<String> refresh(
    ) {
        business.refresh();
        return ResultModel.success();
    }
    
    @PutMapping("/sale-price")
    @ApiOperation("设置售价")
    @Loggable(module = Module.FILM_SCHEDULE, desc = "设置售价")
    public ResultModel<String> setSalePrice(
        @RequestBody SalePriceInput input
    ) {
        // 这里可以编写设置开售渠道的业务逻辑
        // 例如，保存到数据库或调用其他服务等操作
        business.setSalePrice(input);
        // 返回成功消息
        return ResultModel.success();
    }
    
    @PutMapping("/sale-channel")
    @ApiOperation("设置开售渠道")
    @Loggable(module = Module.FILM_SCHEDULE, desc = "设置开售渠道")
    public ResultModel<String> setSaleChannel(
        @RequestBody SaleChannelInput input
    ) {
        // 这里可以编写设置开售渠道的业务逻辑
        // 例如，保存到数据库或调用其他服务等操作
        business.setSaleChannel(input);
        // 返回成功消息
        return ResultModel.success();
    }
    
    @GetMapping("/sale-films")
    @ApiOperation("排期在售影片")
    public ResultModel<PageModel<SaleFilmListOutput>> saleFilmList(
        @Valid SaleFilmListInput input
    ) {
        // 返回成功消息
        return ResultModel.success(
            business.saleFilmList(input)
        );
    }
    
    @PutMapping("/sort")
    @ApiOperation("排期影片排序")
    public ResultModel<String> setSort(
        @RequestBody @Valid FilmSortInput input
    ) {
        business.setSort(input);
        // 返回成功消息
        return ResultModel.success();
    }
}
